﻿using Model;
using System;
using System.Collections.Generic;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    /// <summary>
    /// 获取相对应的用户的权限
    /// </summary>
    public  class ModuleService
    {
        public static Module GetModule(string contollerName,string actionName)
        {
            using (ShopDemoContextt db = new ShopDemoContextt())
            {
                return db.Module.FirstOrDefault(p => p.ControllerName == contollerName&&p.ActionName==actionName);
            }
        }
        /// <summary>
        /// 获取模块信息
        /// </summary>
        /// <returns></returns>
        public static List<Module> GetModelsMsg()
        {
            using (ShopDemoContextt db = new ShopDemoContextt())
            {
                return db.Module.ToList();
            }
        }

        /// <summary>
        /// 添加模块信息
        /// </summary>
        /// <param name="module"></param>
        /// <returns></returns>
        public static int GetAdd(Module module)
        {
            using (ShopDemoContextt db = new ShopDemoContextt())
            {
                db.Module.Add(module);
                return db.SaveChanges();
            }
        }
        /// <summary>
        /// 删除模块信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static int GetDel(int id)
        {
            using (ShopDemoContextt db = new ShopDemoContextt())
            {
                Module module = new Module() { Id = id };
                db.Module.Attach(module);
                db.Module.Remove(module);
                return db.SaveChanges();
            }
        }
        /// <summary>
        /// 根据id查询模块信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Module GetSelect(int id)
        {
            using (ShopDemoContextt db = new ShopDemoContextt())
            {
                return db.Module.FirstOrDefault(p => p.Id == id);
            }
        }
        /// <summary>
        /// 修改模块信息
        /// </summary>
        /// <param name="module"></param>
        /// <returns></returns>
        public static int GetUpdate(Module module)
        {
            using (ShopDemoContextt db = new ShopDemoContextt())
            {
                db.Module.AddOrUpdate(module);
                return db.SaveChanges();
            }
        }
    }
}
